package cn.dengta.webapp.trade.entity;

import java.util.Date;

import cn.dengta.webapp.base.entity.BaseEntity;
import cn.dengta.webapp.base.entity.TimeBasedEntity;
import cn.dengta.webapp.user.entity.userLevel.UserLevelRule.UserLevelRuleType;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import me.codeplayer.util.X;

/**
 * 用户等级记录表
 *
 * @author lgy
 * @since 2022-11-28
 */
@Setter
@Getter
@Accessors(chain = true)
@TableName("dt_user_level_log")
public class UserLevelLog extends TimeBasedEntity {

	/** 用户ID */
	Long userId;
	/** 业务类型 */
	UserLevelRuleType ruleType;
	/** 经验 */
	Integer exp;
	/** 原始经验 */
	Long oldExp;
	/** 当前经验 */
	Long currentExp;
	/** 操作目标类型 */
	String assocType;
	/** 操作目标ID */
	Long assocId;
	Integer status;

	public UserLevelLog init(Long userId, UserLevelRuleType ruleType, Integer exp, Long oldExp, Long currentExp, BaseEntity assocBean, Date now) {
		this.userId = userId;
		this.ruleType = ruleType;
		this.exp = exp;
		this.oldExp = oldExp;
		this.currentExp = currentExp;
		this.assocType = X.map(assocBean, BaseEntity::entityName);
		this.assocId = X.map(assocBean, BaseEntity::getId);
		super.initTime(now);
		return this;
	}

	public static final String USER_ID = "user_id";
	public static final String RULE_TYPE = "rule_type";
	public static final String EXP = "exp";
	public static final String ASSOC_TYPE = "assoc_type";
	public static final String ASSOC_ID = "assoc_id";
	public static final String STATUS = "status";

}
